const baseUrl = ''
interface ParamModel{
  data ?: object
  header ?: object
  method ?: 'GET' | 'POST'
}

enum HttpMethod{
  GET,POST
}

interface RequestConfig{
  url?: string
  method?: HttpMethod
  data?: any
  needToken?:boolean
  header?:object
}



export default function request(url:string,params:ParamModel){
  return new Promise(function(resolve,reject){
    wx.showLoading({
      title:'加载中...'
    })
    wx.request({
      url:baseUrl + url,
      data:params.data || {},
      header:params.header || {},
      method : params.method || 'GET',
      dataType : 'json',
      success:function(res){
        wx.hideLoading()
        resolve(res.data)
      },
      fail:function(err){
        wx.hideLoading()
        wx.showToast({
          title:err || '请求错误'
        })        
        reject(err)
      }
    })
  })
}